package cn.wolfcode.shop.cloud.common;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class Result<T> implements Serializable {
    public static final int SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG = "操作成功";
    public static final int DEFAULT_ERROR_CODE = 50001;
    public static final String DEFAULT_ERROR_MSG = "系统异常";
    private int code;
    private String msg;
    private T data;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(T data) {
        this.data = data;
    }

    public static <T> Result<T> success(T data) {

        return new Result(SUCCESS_CODE, SUCCESS_MSG, data);

    }

    public static Result defaultError() {

        return new Result(DEFAULT_ERROR_CODE, DEFAULT_ERROR_MSG, null);

    }
    public static Result Error(CodeMsg codeMsg) {

        return new Result(codeMsg.getCode(), codeMsg.getMsg(), null);

    }



}
